
namespace Core {
    export class SceneManager extends BaseClass {
        private _scenes: any;
        private _currScene: number;

        public constructor() {
            super();
            this._scenes = {};
        }

        public register(key: number, scene: BaseScene): void {
            this._scenes[key] = scene;
        }

        public clear(): void {
            var nowScene: BaseScene = this._scenes[this._currScene];
            if (nowScene) {
                nowScene.onExit();
                this._currScene = undefined;
            }
            this._scenes = {};
        }

        public runScene(key: number, ...param: any[]): void {
            var nowScene: BaseScene = this._scenes[key];
            if (nowScene == null) {
                console.log("场景" + key + "不存在");
                return;
            }

            var oldScene: BaseScene = this._scenes[this._currScene];
            if (oldScene) {
                oldScene.onExit();
            }

            nowScene.onEnter.apply(nowScene, param);
            this._currScene = key;
        }

        public getCurrScene(): number {
            return this._currScene;
        }
    }
}